package cn.italkcloud.cph.constants.enums;

import cn.italkcloud.cph.utils.StringUtil;
import lombok.Getter;
import org.springframework.util.CollectionUtils;

import java.util.*;

@Getter
public enum PermViewEnum {
    /**
     * 基础页面访问
     */
    BASE("0", "基础页面", "/"),
    /**
     * 用户首页，统计数据等
     */
    HOME("1", "用户首页", "/home"),

    VOS_CUSTOMER("2-1", "VOS账户管理", "/vos/customer", "/vos"),
    VOS_FEE_LOG("2-2", "VOS费用明细", "/vos/fee", "/vos"),
    VOS_SERVER("2-3", "VOS服务器管理", "/vos/server", "/vos"),
    VOS_GROUP("2-4", "VOS账户组", "/vos/group", "/vos"),

    REPORT_VOS_CUSTOMER_FEE("3-1", "报表VOS账户费用", "/report/vos-customer-fee", "/report"),
    REPORT_VOS_GATEWAY_FEE("3-2", "报表VOS网关费用", "/report/vos-gateway-fee", "/report"),
    ;

    private final String id;
    private final String desr;
    private final String path;
    private final String sign;


    PermViewEnum(String id, String desr, String path) {
        this(id, desr, path, StringUtil.EMPTY);
    }

    PermViewEnum(String id, String desr, String path, String sign) {
        this.path = path;
        this.id = id;
        this.desr = desr;
        this.sign = sign;
    }

    public static List<String> getIds() {
        List<String> ids = new ArrayList<>();
        for (PermViewEnum value : values()) {
            ids.add(value.getId());
        }
        return ids;
    }

    public static Map<String, String> getPathMap() {
        Map<String, String> pathMap = new HashMap<>();
        for (PermViewEnum value : values()) {
            pathMap.put(value.getId(), value.getPath());
        }
        return pathMap;
    }

    public static List<String> getPathList(List<String> idList) {
        if (CollectionUtils.isEmpty(idList)) {
            return Collections.emptyList();
        }
        Map<String, String> pathMap = getPathMap();
        List<String> pathList = new ArrayList<>(idList.size());
        for (String id : idList) {
            pathList.add(pathMap.get(id));
        }
        return pathList;
    }
}
